<?php
/**
 * TinyCorePHP
 * tiny but core php mvc framework
 * @author 	itkele@gmail.com
 * @date 	2012-11-21
 */
!defined('IN_SITE') && define('IN_SITE',true);
!defined('APP_ROOT') && define('APP_ROOT', str_replace('\\','/',dirname(__FILE__)));
define('TINY_VERSION',0.2);

require_once 'config.php';
require_once 'common.php';
require_once 'functions.php';
require_once 'Db.class.php';
require_once 'Control.class.php';
require_once 'Model.class.php';

class Tiny{

	public function run(){
		$components = (string)trim($_GET['com']);
		$control = empty($_GET['a']) ? 'index' : (string)trim($_GET['a']);
		$method = empty($_GET['m']) ? 'index' : (string)trim($_GET['m']);
		$className = ucfirst($control).'Control';
		if( ! empty($components)){
			$file = APP_ROOT . '/components/com_' . strtolower($components) . '/control/' . $className . '.class.php';
		}else{
			$file = APP_ROOT . '/control/' . $className . '.class.php';
		}
		(file_exists($file) && require_once $file) or die('File "' . $className . '.class.php" not found.');
		if(class_exists($className)){
			$class = new $className();
			if(method_exists($class,$method) || (method_exists($class,'index') && $method = 'index')){
				call_user_func(array($class,$method));
			}else{
				die('Method '.$method.' not found.');
			}
		}else{
			die('Class '.$className.' not found.');
		}
	}
}